package com.xml.expand;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author yangSen
 * @Date 2022年01月13日 10:00
 */
public class MyClassPathXmlApplicationContext extends ClassPathXmlApplicationContext {


	public MyClassPathXmlApplicationContext(String... configLocations) {
		super(configLocations);
	}

	/**
	 * 继承方法,进行拓展 , 可以参考
	 *
	 * @see AbstractApplicationContext#initPropertySources()
	 * @see org.springframework.web.context.support.WebApplicationContextUtils#initPropertySources()
	 */
	@Override
	protected void initPropertySources() {
		System.out.println("expand  initPropertySources .....");
		//将 username 设置为系统属性值 , 还可以设置其他东西
		getEnvironment().setRequiredProperties("username");
	}

	/**
	 * 此方法可以选择是否自定解决循环依赖,是否允许bean定义信息覆盖 , 这两个属性原来默认为 true
	 *
	 * @param beanFactory the newly created bean factory for this context
	 */
	@Override
	protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
//		super.setAllowBeanDefinitionOverriding(false);
//		super.setAllowCircularReferences(false);
		super.customizeBeanFactory(beanFactory);
	}
}
